// auth.js
export const userManager = {
    // 设置登录状态
    setLoginStatus: function(email) {
        localStorage.setItem('isLoggedIn', 'true');
        localStorage.setItem('currentUser', email);
    },

    // 清除登录状态
    clearLoginStatus: function() {
        localStorage.removeItem('isLoggedIn');
        localStorage.removeItem('currentUser');
    },

    // 获取当前用户
    getCurrentUser: function() {
        return localStorage.getItem('currentUser');
    },

    // 检查用户是否存在
    userExists: function(email) {
        const users = this.getUsers();
        return users.some(user => user.username === email);
    },

    // 保存用户
    saveUser: function(user) {
        const users = this.getUsers();
        users.push(user);
        localStorage.setItem('users', JSON.stringify(users));
    },

    // 获取所有用户
    getUsers: function() {
        return JSON.parse(localStorage.getItem('users') || '[]');
    },

    // 初始化用户存储
    init: function() {
        if (!localStorage.getItem('users')) {
            localStorage.setItem('users', JSON.stringify([]));
        }
    }
};

// 初始化用户存储
userManager.init();